let category = new Vue({
    el:"#categoryApp",
    data:{
        items:{},
        category:""
    },
    methods:{
        getCategory:function () {
            let qid = location.search;
            if (!qid){
                this.getItems();
                return;
            }
            qid = qid.substring(1);
            axios({
                url:"/category/items/"+qid,
                method:"get"
            }).then(function (response) {
                console.log(response.data)
                category.items = response.data;
            })
        },
        getItems:function () {
            axios({
                url:"/category/items",
                method:"get"
            }).then(function (response) {
                console.log(response.data)
                category.items = response.data;
            })
        },
        categoryCatName:function () {
            let qid = location.search;
            if (!qid) {
                this.category = "全部商品";
                return;
            }
            qid = qid.substring(1);
            axios({
                url:"/category/"+qid,
                method:"get"
            }).then(function (response) {
                console.log(response.data)
                category.category = response.data;
            })
        }
    },
    created:function () {
        this.getCategory(); //获取商品
        this.categoryCatName(); //查询分类名称
    }
})